package com.frinder.seata.data.domain.web;

import com.frinder.seata.data.base.Result;
import com.frinder.seata.data.base.PageWrapper;
import com.frinder.seata.data.base.ModelWrapper;
import com.frinder.seata.data.domain.model.Account;
import com.frinder.seata.data.domain.service.IAccountService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import java.util.List;

/**
* Created by frinder on 2020/08/18.
*/
@RestController
@RequestMapping("/account")
public class AccountController {
    @Resource
    private IAccountService accountService;

    @ApiOperation(value = "添加 Account")
    @PostMapping("/add")
    public Result add(@RequestBody Account account) {
        accountService.save(account);
        return Result.defSuccess();
    }

    @ApiOperation(value = "根据 id 删除 Account")
    @GetMapping("/delete")
    public Result delete(@RequestParam Long id) {
        accountService.deleteById(id);
        return Result.defSuccess();
    }

    @ApiOperation(value = "根据 ids 批量删除 Account")
    @GetMapping("/deleteByIds")
    public Result deleteByIds(@RequestParam String ids) {
        accountService.deleteByIds(ids);
        return Result.defSuccess();
    }

    @ApiOperation(value = "更新 Account")
    @PostMapping("/update")
    public Result update(@RequestBody Account account) {
        accountService.update(account);
        return Result.defSuccess();
    }

    @ApiOperation(value = "根据 id 查询 Account")
    @GetMapping("/detail")
    public Result detail(@RequestParam Long id) {
        Account account = accountService.findById(id);
        return Result.dataSuccess(account);
    }

    @ApiOperation(value = "按条件查询 Account")
    @PostMapping("/listByModelWrapper")
    public Result listByModelWrapper(@RequestBody ModelWrapper<Account> wrapper) {
        List<Account> list = accountService.findByModelWrapper(wrapper);
        return Result.dataSuccess(list);
    }

    @ApiOperation(value = "按条件分页查询 Account")
    @PostMapping("/page")
    public Result page(@RequestBody PageWrapper<Account> page) {
        PageInfo pageInfo = accountService.page(page);
        return Result.dataSuccess(pageInfo);
    }
}
